@extends('admin.common.base-master')

@section('html-head')
    {{--<link href="{{url('/vendor/tyupload/control/css/zyUpload.css')}}" type="text/css" rel="stylesheet" />--}}
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    {{--<script src="{{url('/vendor/My97DatePicker/WdatePicker.js')}}"></script>--}}
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>

    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script type="text/javascript" src="//code.jquery.com/ui/1.9.1/jquery-ui.min.js"></script>

    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
    @include('UEditor::head')
@endsection

@section('html-body')
    <!-- content start -->

    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            @if($type == 'about_us')
                <a href="{{route('Admin.Home.aboutUsList')}}">关于我们</a>
            @else
                <a href="{{route('Admin.Home.enAboutUsList')}}">关于我们</a>
            @endif
            <em>></em>
            <a href="#">内容设置</a>
        </div>

        @include('admin.common.about-us-header')

        <div class="gg-step">
            <form  id="advform">
                <input type="hidden" name="id" id="goodsid" value="@if($thisAboutUs && $thisAboutUs->id){{$thisAboutUs->id}} @endif"/>
                <input type="hidden" name="type" id="type" value="{{$type}}"/>
                <div class="gg-list">
                    <label class="tit">所属分类</label>
                    <div class="cont">
                        <label class="gg-radio">
                            <select id="classify_id">
                                @if(!$thisAboutUs || $thisAboutUs->classify_id == 0 || $thisAboutUs->classify_id != '')
                                    <option value="0">请选择分类</option>
                                @endif
                                @foreach($classifies as $classify)
                                    <option value="{{$classify->id}}" @if($thisAboutUs && $thisAboutUs->classify_id == $classify->id)selected @endif>{{$classify->name}}</option>
                                @endforeach
                            </select>
                        </label>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">关于我们</label>
                    <textarea name="description" id="aa"></textarea>
                </div>

                <div class="gg-list">
                    <label class="tit">状态</label>
                    <div class="cont">
                        <select name="is_show" id="is_show">
                            <option value="1" @if($thisAboutUs && $thisAboutUs->is_show == 1) selected @endif>显示</option>
                            <option value="0" @if($thisAboutUs && $thisAboutUs->is_show == 0) selected @endif>隐藏</option>
                        </select>
                        <p class="text">选择显示或蕴藏</p>
                    </div>
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn-set">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>
        $(function() {

            <!-- 实例化编辑器 -->
            var ue = UE.getEditor('aa',{
                autoHeightEnabled: true,
                initialFrameHeight:400,
                initialFrameWidth:600,
                toolbars: [
                    ['fullscreen', 'source','undo','redo','|','fontsize','horizontal','|','simpleupload','insertvideo','removeformat'],
                    ['bold', 'italic', 'underline', 'forecolor', 'backcolor','|','indent','|','justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight','|','insertunorderedlist', 'insertorderedlist','|', 'imagenone','imageleft','imageright','imagecenter','|','link']
                ]
            });

            @if($thisAboutUs)
            ue.ready(function() {
                        ue.setContent('<?php echo $thisAboutUs->content ?>');
                    });
            @endif

            $(document).on('click', '#btn-set', function () {
                var content = "";

                ue.ready(function() {
                    content = ue.getContent();
                });
                var isShow       = $('#is_show option:selected').val();
                var classifyId   = $('#classify_id option:selected').val();
                var type         = $('#type').val();
                var id           = $('#goodsid').val();

                $.ajax({
                    url: '{{route("Api.Admin.sys.setAboutUs")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        content:content,
                        is_show:isShow,
                        classify_id:classifyId,
                        type:type,
                        id:id
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        if(type == 'about_us'){
                                            window.location.href = "{{route('Admin.Home.aboutUsList')}}";
                                        }else{
                                            window.location.href = "{{route('Admin.Home.enAboutUsList')}}";
                                        }
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });
        });
    </script>

@endsection